// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   MenuServiceImpl.java

package com.hfstu.ifs.dataaccess.service.impl;

import com.google.common.collect.Maps;
import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.ifs.dataaccess.dao.IMenuDao;
import com.hfstu.ifs.dataaccess.service.IMenuService;
import com.hfstu.ifs.model.Menu;
import java.io.Serializable;
import java.util.*;

public class MenuServiceImpl
	implements IMenuService
{

	private IMenuDao menuDao;

	public MenuServiceImpl()
	{
		menuDao = null;
	}

	public Menu save(Menu menu)
	{
		return (Menu)menuDao.save(menu);
	}

	public Menu getById(String id)
	{
		return (Menu)menuDao.getById(id);
	}

	public Menu update(Menu menu)
	{
		return (Menu)menuDao.update(menu);
	}

	public Menu saveOrUpdate(Menu menu)
	{
		return (Menu)menuDao.saveOrUpdate(menu);
	}

	public List getByIds(String ids[])
	{
		return menuDao.getByIds(ids);
	}

	public void delete(String id)
	{
		menuDao.delete(id);
	}

	public void delete(Menu entity)
	{
		menuDao.delete(entity);
	}

	public List findAll()
	{
		return menuDao.findAll();
	}

	public List findListByCondition(Map filterPropertyMap, Map sortValueMap)
	{
		if (sortValueMap == null)
		{
			sortValueMap = Maps.newHashMap();
			sortValueMap.put("menu.orderIndex", "ASC");
		}
		return menuDao.findListByCondition(filterPropertyMap, sortValueMap);
	}

	public Page findPageByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		if (sortValueMap == null)
		{
			sortValueMap = Maps.newHashMap();
			sortValueMap.put("orderIndex", "ASC");
		}
		return menuDao.findPageByCondition(pageRequest, filterPropertyMap, sortValueMap);
	}

	public void deleteAllById(String id)
	{
		List childrenIds = getAllChildrenId(id);
		if (childrenIds != null && childrenIds.size() != 0)
			menuDao.deleteByIds((String[])childrenIds.toArray(new String[childrenIds.size()]));
		menuDao.delete(id);
	}

	public List getAllChildrenId(String id)
	{
		List results = null;
		Map filterPropertyMap = new HashMap();
		filterPropertyMap.put("menu.parentId", id);
		List list = menuDao.findListByCondition(filterPropertyMap, null);
		if (list != null && list.size() != 0)
		{
			results = new ArrayList();
			for (Iterator iterator = list.iterator(); iterator.hasNext();)
			{
				Menu menu = (Menu)iterator.next();
				results.add(menu.getId());
				List childrens = getAllChildrenId(menu.getId());
				if (childrens != null)
					results.addAll(childrens);
			}

		}
		return results;
	}

	public List getAllParentId(String id)
	{
		List results = null;
		Menu menu = (Menu)menuDao.getById(id);
		if (menu != null)
		{
			results = new ArrayList();
			List parentIds = getAllParentId(menu.getParentId());
			if (parentIds != null)
			{
				results.add(menu.getParentId());
				results.addAll(parentIds);
			}
		}
		return results;
	}

	public IMenuDao getMenuDao()
	{
		return menuDao;
	}

	public void setMenuDao(IMenuDao menuDao)
	{
		this.menuDao = menuDao;
	}

	public volatile Object getById(Serializable serializable)
	{
		return getById((String)serializable);
	}

	public volatile Object save(Object obj)
	{
		return save((Menu)obj);
	}

	public volatile Object saveOrUpdate(Object obj)
	{
		return saveOrUpdate((Menu)obj);
	}

	public volatile void delete(Object obj)
	{
		delete((Menu)obj);
	}

	public volatile void delete(Serializable serializable)
	{
		delete((String)serializable);
	}

	public volatile List getByIds(Serializable aserializable[])
	{
		return getByIds((String[])aserializable);
	}

	public volatile Object update(Object obj)
	{
		return update((Menu)obj);
	}
}
